package LinkedList和HashSet和HashMap.work06;
import java.util.*;
public class HashSetTest {

    public static void main(String[] args) {
        //创建随机生成器
        Random random = new Random();
        Set<Integer> redBallSet = new HashSet<>();
        //生成6个不重复红色球
        while(redBallSet.size() != 6){
            //生成【1-33】范围内的随机整数
            int redBall = random.nextInt(33) + 1;
            redBallSet.add(redBall);
        }

        Set<Integer> sortSet = new TreeSet<>((o1,o2) -> o1.compareTo(o2));
        sortSet.addAll(redBallSet);
        System.out.println(sortSet.toString());
        StringBuffer buffer = new StringBuffer();
        Iterator<Integer> iter = sortSet.iterator();
        while(iter.hasNext()){
            Integer redBall = iter.next();
            buffer.append(redBall + " ");
        }

        for (Integer redBall : sortSet) {
            buffer.append(redBall);
            buffer.append(",");
        }

        //生成【1~16】范围内的随机整数
        int blueBall = random.nextInt(16) + 1;

        String redStr = buffer.deleteCharAt(buffer.toString().length() - 1).toString();
        System.out.println("随机生成的双色球是：" + redStr + "+" + blueBall);


    }

}
